﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using iPick.Business;
using System.Data.EntityModel;

namespace iPick.Controllers
{
      

    public class SettingsController : Controller
    {
        protected iPick.Models.Application ApplicationModel = null;
        //
        // GET: /Settings/
        [Header("Settings")]
        public ActionResult Index()

        {
            iPick.Business.ApplicationModelHelper.SetSession();
            if(Session[iPick.Business.ApplicationModelHelper.Keys.ApplicationModel]==null)
            ApplicationModel = iPick.Business.ApplicationModelHelper.getModelPopulated(ApplicationModel);
            else
            ApplicationModel = (iPick.Models.Application)(Session[iPick.Business.ApplicationModelHelper.Keys.ApplicationModel]);

            return View(ApplicationModel);
   
        }

        [HttpPost]
        public ActionResult Index( FormCollection form)
        {
            iPick.Business.ApplicationModelHelper.SetSession();
            iPick.Controllers.DataServiceController DataService = new Controllers.DataServiceController();
            ApplicationModel= (iPick.Models.Application)(Session[iPick.Business.ApplicationModelHelper.Keys.ApplicationModel]);
            ApplicationModel.CustomerDevice.NumberOfItemsToDisplay=Convert.ToInt64(form["slider"].ToString());
            //ApplicationModel.CustomerDevice.DeviceKey = form["hiddenDKey"].ToString();

            Session[iPick.Business.ApplicationModelHelper.Keys.ApplicationModel]=null;
           ApplicationModel.CustomerDevice= DataService.UpdateCustomerDevice(ApplicationModel.CustomerDevice.DeviceKey, ApplicationModel.CustomerDevice);
            return View(ApplicationModel);
        }

    }
}
